package com.zjw.service.impl;

import com.zjw.entity.po.MeetingPub;
import com.zjw.entity.po.MeetingType;
import com.zjw.mapper.MeetingPubMapper;
import com.zjw.service.MeetingPubService;
import com.zjw.service.MeetingTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
public class MeetingPubServiceImpl implements MeetingPubService {
    @Autowired
    private MeetingPubMapper meetingPubMapper;

    @Override
    public List<MeetingPub> selectMeetingPubsByUid(int uid) {
        return meetingPubMapper.selectMeetingPubsByUid(uid);
    }

    /**
     * 会议添加功能
     * @param pub
     * @return
     */
    @Override
    public int insertSelective(MeetingPub pub) {

        pub.setId(UUID.randomUUID().toString());
        pub.setCreatedate(new Date());
        pub.setStatus((short)1);

        pub.setPcode(this.getPcode(pub.getPtime()));

        return meetingPubMapper.insertSelective(pub);
    }



    public String getPcode(String ptime){
        //1字符串截取   20210101
        String time = ptime.substring(0, 10).replace("-", "");
        //
        String s = meetingPubMapper.selectMaxPcodeByPtime(time);
        if (StringUtils.isEmpty(s)){
            return time+"001";
        }else {
            long num = Long.parseLong(s)+ 1;
            return num+"";
        }
    }
}
